package cn.timelost.hr.controller;


import cn.timelost.hr.enums.ResultEnum;
import cn.timelost.hr.utils.FileUploadUtils;
import cn.timelost.hr.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author: Jyf
 * @Date: 2021/1/31 17:39
 */
@RestController
@Slf4j
public class ImageController extends BaseController {
    
    @Resource
    private FileUploadUtils fileUploadUtils;
    
    @PostMapping("/image/upload")
    public ResultVo upload(@RequestParam("file") MultipartFile multipartFile) throws Exception {
        String imgUrl = fileUploadUtils.upload(multipartFile);
        if (imgUrl != null) {
            log.info(imgUrl);
            return ResultVo.success(imgUrl);
        }
        return ResultVo.fail(ResultEnum.UPLOAD_FAIL);
    }
}